﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RWLib
{
    public class Node
    {
        public List<StatementBase> actions = new List<StatementBase>();
        public List<StatementBase> notDone = new List<StatementBase>();
        public List<Node> Nodes = new List<Node>();
        public List<Fluent> Fluents=new List<Fluent>();
        public List<List<Fluent>> states=new List<List<Fluent>>();
        public int t = 0;

        public Node() { }

        public Node(List<Fluent> fluents)
        {
            fluents.CopyTo(Fluents);
        }
        
        public Node(List<Fluent> fluents, List<Node> nodes, List<StatementBase> _actions)
        {
            Fluents = new List<Fluent>();
            fluents.CopyTo(Fluents);
            Nodes = nodes;
            actions = _actions;
        }

        public Node(List<Fluent> fluents, List<Node> nodes, List<StatementBase> _actions, int _t, List<StatementBase> _notDone)
        {
            Fluents = new List<Fluent>();
            fluents.CopyTo(Fluents);
            Nodes = nodes;
            actions = _actions;
            notDone = _notDone;
            t = _t;
        }

        public Node(List<Fluent> fluents, List<Node> nodes, List<StatementBase> _actions, int _t)
        {
            Fluents = new List<Fluent>();
            fluents.CopyTo(Fluents);
            Nodes = nodes;
            actions = _actions;
            t = _t;
        }

        public List<List<Fluent>> States {
            get { return states; }
            set { states = value; }
        }

        public Node Clone()
        {
            return new Node(Fluents, Nodes,actions,t,notDone);
        }

        public override string ToString()
        {
            var sb = new StringBuilder();
            sb.Append("====================================");
            sb.Append("\nTime: (");
            sb.Append(t);
            sb.Append(",");
            sb.Append(t+1);
            sb.Append(") : ");
            sb.Append(String.Concat(Fluents.Select(o => o.Name + " : " + o.Value + " , ")));
            sb.Append("\nActions: ");
            sb.Append(String.Concat(actions.Select(o => o.Name + " , ")));
            sb.Append("\n");
            sb.Append("====================================");
            sb.Append("\n");
            return sb.ToString();
        }
    }
}
